package com.lsa.helpers.tree;

public class Tree<T> implements ITree<T>
{
    protected ITreeNode<T> root;
    
    public Tree(ITreeNode<T> root)
    {
        this.root = root;
    }

    @Override
    public ITreeNode<T> getRoot()
    {
        return root;
    }
    
    protected void setRoot(ITreeNode<T> root) {
		this.root = root;
	}

	@Override
    public int size()
    {
        return count(getRoot());
    }
    
    private int count(ITreeNode<T> root){
        if (root == null) return 0;
        int count = 1;
        for( ITreeNode<T>  childNode : root.getChildren() )
        {
            count += count(childNode);
        }
        return count;
    }
}
